--[[
卡片显示 
]]
local CardUtil =  require("app.util.CardUtil")
local CardInfoSprite =  require("app.views.editor.CardInfoSprite")
local WorldLevelData = require("app.data.level.WorldLevelData")
local CardListSprite = class("CardListSprite", BaseSprite)




function CardListSprite:initView()
    local card_nums = WorldLevelData.card_nums;
    
    --初始化卡牌
	for i = 1,card_nums,1 do
		local PUSH_BUTTON_IMAGES = {
		    normal = "#cardSprite_"..i.."_0.png" or "cardSprite_1_0.png";
		    pressed = "#cardSprite_"..i.."_1.png" or "cardSprite_1_1.png";
		    disabled = "#cardSprite_"..i.."_1.png" or "cardSprite_1_1.png";
		}
		cc.ui.UIPushButton.new(PUSH_BUTTON_IMAGES, {scale9 = true})
        --:setButtonSize(CardUtil.width, CardUtil.width)
        :setButtonLabelOffset(0, -CardUtil.height/2)
         :setButtonLabel("normal", cc.ui.UILabel.new({
            UILabelType = 2,
            text = "卡片id："..i,
            size = 18
        }))
        :setScale(0.5)
		:onButtonClicked(function(event)
            local button = event.target
            self:touchByCardSprite(event,i)
            return true
        end)
        --:setPosition((i-1)*CardUtil.width,0)
        :align(display.BOTTOM_LEFT, (i-1)*CardUtil.width,10)
        :addTo(self)
	end
end






--事件响应
function CardListSprite:touchByCardSprite(event,cardSpriteId)
	echoj("当前选中的",cardSpriteId,event);
	self.targetCard_:setCardSpriteId(cardSpriteId);
	self.object_.CardInfoSprite_:updateView(self.targetCard_);
end





function CardListSprite:updateView(targetCard)
	self.targetCard_ =targetCard;
end


return CardListSprite
